from superdice.superdice import registerRoll, unregisterRoll, players
from superdice.libs.playerExtras import getPlayer

def unload():
    unregisterRoll(diceRoll)

def player_spawn(ev):
    players[ev['userid']]['respawn'] = False

def player_death(ev):
    userid = ev['userid']
    if not players[userid]['respawn']:
        return

    getPlayer(userid).respawnPlayer()

def diceRoll(userid, player, eplayer):
    players[userid]['respawn'] = True

registerRoll(diceRoll, 'respawn')
